package com.runa.rccprotocol.dto.en;

import com.runa.protocol.dto.IResponseData;
import com.runa.protocol.util.ByteUtil;
import com.runa.rccprotocol.dto.ConcentratorRequestData;

/**
 * @author diandian
 * @Date 2021/11/1 9:53
 */
public class EnMeterRequestData extends ConcentratorRequestData {
    public EnMeterRequestData(String address) {
        super(address);
    }

    @Override
    public boolean check(IResponseData data) {
        return true;
    }

    @Override
    public byte[] getData() {
        return requestData;
    }

    private byte[] requestData;


    public void init() {
        requestData = new byte[]{0x10, 0x40, (byte) 0xFD, 0, 0x16};
        requestData[3] = ByteUtil.sum(requestData, 0, 3);
        setHaveResult(true);
    }

    public void choseHouseMeter(String meterNo) {
        requestData = new byte[]{0x68, 0x0B, 0x0B, 0x68, 0x53, (byte) 0xFD, 0x52, 0, 0, 0, 0, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0, 0x16};
        ByteUtil.tenstringToBcd(requestData, meterNo, 7, false);
        requestData[15] = ByteUtil.sum(requestData, 4, 11);
        setHaveResult(true);
    }

    public void readHouseMeter() {
//        10 5B FD 58 16
        requestData = new byte[]{0x10, 0x5B, (byte) 0xFD, 0, 0x16};
        requestData[3] = ByteUtil.sum(requestData, 1, 2);
        setHaveResult(true);
    }

    public void destroy() {
        requestData = new byte[]{0x10, 0x40, (byte) 0xFD, 0, 0x16};
        requestData[3] = ByteUtil.sum(requestData, 1, 2);
        setHaveResult(true);
    }

    public static void main(String[] args) {
        byte a[] = new byte[]{0x10, 0x5B, (byte) 0xFD, 0, 0x16};
        a[3] = ByteUtil.sum(a, 1, 2);
        System.out.println(ByteUtil.byteToHexString(a));

    }


}